#include "client.hpp"

int main(int argc, char const *argv[])
{
    if(argc < 3)
    {
        fprintf(stderr,"[file:%s,func:%s,line:%d] argc is invalid!\n",__FILE__,__func__,__LINE__);
        exit(-1);
    }

    client* ptclient = nullptr;
    Framebuffer *ptFramebuffer = nullptr;

    try
    {
        ptclient      = new client();
        ptFramebuffer = new Framebuffer();
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
    }
    
    ptFramebuffer->Init();

    ptFramebuffer->getFramebufferinfo();

    ptclient->new_resized_rgb_data(ptFramebuffer);

    ptclient->Init(argv);

    while(1)
    {
        ptclient->recv_rgb_data(ptFramebuffer);

        /* 刷白屏 */
        // memset(ptFramebuffer->fbMapMem, 0x00, ptFramebuffer->screen_size);

        // ptFramebuffer->display_rgb_to_framebuffer(ptclient->rgb_data[ptclient->n - 1], HEIGHT, WIDTH);
        ptFramebuffer->display_rgb_to_framebuffer(ptclient->resized_rgb_data[ptclient->n - 1], ptFramebuffer->iHeight, ptFramebuffer->iWidth);
    }

    ptFramebuffer->closeFramebuffer();
    delete ptFramebuffer;
    delete ptclient;
    return 0;
}